package com.goomba.order;

import com.goomba.demo.contants.Commons;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.common.message.MessageExt;



public class Consumer {


    public static void main(String[] args) throws Exception {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("order_group1");

        consumer.setNamesrvAddr(Commons.nameSrvAddr);


        consumer.subscribe("sync_order_topic", "tag1");

        // MessageListenerOrderly
        consumer.registerMessageListener((MessageListenerOrderly) (list, consumeOrderlyContext) -> {

            System.out.println(consumeOrderlyContext.getMessageQueue().getQueueId());
            for (MessageExt ext : list) {
                System.out.println(Thread.currentThread().getName() + ":" + "接收到的消息是 " + new String(ext.getBody()));
            }

            return ConsumeOrderlyStatus.SUCCESS;
        });


        consumer.start();
        System.out.println("消费端启动成功......");

    }
}
